/**
 * 
 */
package junit;

import java.util.Date;

import es.uab.es2.TimeTracker.nucli.Rellotge;
import junit.framework.TestCase;

/**
 * @author sule
 *
 */
public class TestRellotge extends TestCase {
    
    private Rellotge clock;
    private static final long DOS_SEGONS = 2000;
    private static final long TRES_SEGONS = 3000;
    private static final long MIL = 1000;
    private static final long DOSMILCENT = 2100;
    
    
    /* (non-Javadoc)
     * @see junit.framework.TestCase#setUp()
     */
    protected final void setUp() throws Exception {
       super.setUp();
       clock = Rellotge.getInstancia();
       
       //dataInici = null;
       //dataFinal = null;
    }
    public final void testPasDeSegonsParell() {
         Date dataIniciParell = null;
         Date dataFinalParell = null;
         Date dataIniciSenar = null;
         Date dataFinalSenar = null;
        long diferencia = 0;
        long incrementTemps = 0;
        
        try {
           // System.out.println("GetTemps");
            
            clock.iniciar();
            //System.out.println("GetTemps");
            dataIniciParell = Rellotge.getDataInicial();
            dataIniciSenar = Rellotge.getDataInicial();
           // dataIniciSenar=Rellotge.getDataInicial();
            Thread.sleep(DOSMILCENT);
            dataFinalParell = Rellotge.getDataActual();
            Thread.sleep(MIL);
            dataFinalSenar = Rellotge.getDataActual();
            //System.out.println("data inicial en milis:\t" + dataInici);
            
            clock.parar();
            Rellotge.setInstancia(null);
            
            
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        long diferenciaSenar = (dataFinalParell.getTime()
        		- dataIniciSenar.getTime());
        long diferenciaParell = (dataFinalParell.getTime() 
        		- dataIniciParell.getTime());

        assertEquals(((dataFinalParell.getTime() 
        		- dataIniciParell.getTime()) / MIL), DOS_SEGONS / MIL);
        assertEquals(((dataFinalSenar.getTime()
        		- dataIniciSenar.getTime()) / MIL), DOS_SEGONS / MIL);
       
    }
    

   
}
